﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>系统主界面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />

    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    @*<script src="~/Content/X-admin/js/xadmin.js"></script>*@
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/echarts/echarts.common.min.js"></script>
    <script src="~/Content/echarts/echarts.min.js"></script>
    <script src="~/Content/Scripts/System/EChartShow.js"></script>
    @*<script src="~/Content/X-admin/MyIcon/iconfont.css"></script>*@
    <script src="~/Content/X-admin/MyIcon/iconfont.js"></script>

    <script type="text/html" id="barDemo">
        @*<a title="再次执行" href="javascript:;" lay-event="view"><i class="layui-icon">&#xe652;</i></a>*@
    </script>
</head>
<body>

    <div style="width:100%">
        <div style="width:70%;height:518px;float:left;">
            <div class="layui-col-sm6 layui-col-md3" style="width: 23%;">
                <div class="layui-card" onclick="pgView('false')">
                    <div class="layui-card-header" style="color:darkgray;height:30px;line-height:30px;border:none;margin-left:3px" >
                        日派工单未完成数
                    </div>
                    <div class="layui-card-body  ">
                        <p id="pg-nofinish" style="font-size: 35px; color: cornflowerblue;">
                        </p>
                        <p id="pg-nofinish-yesterday" class="iconfont" style="font-size: 10px; color: darkgray; text-align: right;margin-top:-10px ">
                            较昨日
                        </p>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm6 layui-col-md3" style="margin-left: 5px; width: 24%;">
                <div class="layui-card">
                    <div class="layui-card-header" style="color: darkgray; height: 30px; line-height: 30px; border: none">
                        日报工不合格数
                    </div>
                    <div class="layui-card-body ">
                        <p id="bg-noQuality" style="font-size: 35px; color: cornflowerblue;">
                            @*<a href="javascript:;" id="bg-noQuality" class="layui-badge layui-bg-cyan layuiadmin-badge""></a>*@
                        </p>
                        <p id="pg-noQuality-yesterday" class="iconfont" style="font-size: 10px; color: darkgray; text-align: right;margin-top:-10px ">
                            较昨日
                        </p>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm6 layui-col-md3" style="margin-left: 8px; width: 24%;">
                <div class="layui-card">
                    <div class="layui-card-header" style="color: darkgray; height: 30px; line-height: 30px; border: none">
                        计划未完成数
                    </div>
                    <div class="layui-card-body ">
                        <p id="pnofinish" style="font-size: 35px; color: cornflowerblue;">
                            @*<a href="javascript:;" id="pnofinish" class="layui-badge layui-bg-cyan layuiadmin-badge"></a>*@
                        </p>
                        <p class="iconfont" style="font-size: 10px; color: darkgray; text-align: right;height:14px ">

                        </p>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm6 layui-col-md3" style="margin-left: 8px; width: 24%;">
                <div class="layui-card" onclick="pgView('true')">
                    <div class="layui-card-header" style="color: darkgray; height: 30px; line-height: 30px; border: none">
                        派工单延期未完成数
                    </div>
                    <div class="layui-card-body ">
                        <p id="pg-delay" style="font-size: 35px; color: cornflowerblue;">
                            @*<a href="javascript:void(0)" id="pg-delay" class="layui-badge layui-bg-cyan layuiadmin-badge" onclick="Details()"></a>*@
                        </p>
                        <p id="pg-delay-yesterday" class="iconfont" style="font-size: 10px; color: darkgray; text-align: right;margin-top:-10px ">
                            较昨日
                        </p>
                    </div>
                </div>
            </div>
            <div id="leftTChart" style="width: 98%; height: 240px; float: left;margin-top:4px"></div>
            <div id="leftMChart" style="width: 98%; height: 180px; float: left;margin-top:4px"></div>
        </div>
        <div style="width:30%;height:300px;float:left">
            <div id="rightTChart" style="width: 99%; height: 250px; float: left;"></div>

            <div id="rightMChart" style="width: 99%; height: 268px; float: left;"></div>
        </div>
        <div style="width:100%;height:400px;float:left;margin-top:5px" id="orderInfo">
          
        </div>

        
    

    </div>

</body>

</html>

<script type="text/javascript">
    var leftTChart = echarts.init(document.getElementById('leftTChart'), '');
    var leftMChart = echarts.init(document.getElementById('leftMChart'), '');
    var rightTChart = echarts.init(document.getElementById('rightTChart'), '');
    var rightMChart = echarts.init(document.getElementById('rightMChart'));//1

    var bgColor = "#fff";
    $(function () {
        NoFinishTask();
        DaysNoQuality();
        PlanNoFinish();
        TaskDelay();
        LeftTChartTotal();
        RightTChartTotal();
        RightMChartTotal();
        LeftMChartTotal();
        BottomPart();

        //解决查看明细时控制台报 layer is not defined 错误的问题
        layui.use(['laypage', 'layer', 'carousel'], function () {
        });

    });

    //日派工单未完成 - 明细
    function pgView(boolValue) {
        let webUrl = "../Statistics/DataView?keyCode=pgView&dataType=" + boolValue;
        OpenPage("详情内容", webUrl);
    }



    function LeftTChartTotal()
    {
        $.ajax({
            url: "../Statistics/QualityTotalData",
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    var d = data.Data;
                    var option = chart_ZHXHGBHG("当日报工数据统计",  d["names"], d["yData"], d["nData"], bgColor);
                    leftTChart.setOption(option);
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
   
    function LeftMChartTotal() {
        $.ajax({
            url: "../Statistics/GongXuDaysPercent",
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    var d = data.Data;
            
                    leftMChart.setOption(chart_MorePie(d));
                } else {
                    layer.msg(data.Message);
                }
            }
        });
      
    }
  
    
    /**
 工序完成情况柱形图
 **/
    function RightMChartTotal() {
        $.ajax({
            url: "../Statistics/GroupTaskTotal",
            dataType: "json",
            data: { dateType: "day", dataCount: "4" },
            type: "POST",
            success: function (rsl) {
                if (rsl.Result) {
                    var d = rsl.Data;
                    var option = Chart_ZhXZX(d.dlist, "班组任务完成", bgColor);
                    rightMChart.setOption(option);
                } else {
                    layer.msg(rsl.Message);
                }
            }
        });
    }
    function RightTChartTotal() {
        $.ajax({
            url: "../Statistics/BaoGongProductQualityPie",
            dataType: "json",
            data: { dateType: "day", dataCount: "5" },
            type: "POST",
            success: function (rsl) {
                if (rsl.Result) {
                  
                    var d = rsl.Data;
                    var option = Chart_Pie02(d, "不合格率统计", bgColor);
                    rightTChart.setOption(option);
                } else {
                    layer.msg(rsl.Message);
                }
            }
        });
    }


    /**
    生产数据汇总
    **/
    function BottomPart() {
        $.ajax({
            url: "../Statistics/SaleOroderInfo",
            dataType: "json",
            data: { dateType: "year", dataCount: "5" },
            type: "POST",
            success: function (rsl) {
                if (rsl.Result) {
                    var d = rsl.Data;
                    $('#orderInfo').empty();
                    var contents = "";
                    for (var i = 0; i < d.length; i++) {
                        //var pro = d[i].proCode + "/" + d[i].proName;
                        ////var num = "<span style='color:#A23BEC'>" + d[i].planNum + "</span>/<span style='color:#3BB9FF'>" + d[i].finishNum+"</span>";
                        //var num = "<span style='color:#A23BEC'>" + parseFloat(d[i].soNum) + "</span>/<span style='color:#3BB9FF'>" + d[i].finishNum + "</span>";
                        //contents += ' <div style ="border:0px solid darkgray;border-radius:5px;height: 100px; width: 19%; background-color:#fff; padding-top:15px; padding-bottom:7px; float:left; margin-left:1%;margin-top:1%" >' +
                        //    '<span style="margin-left:3%;width:90%;float:left">销售订单号：' + d[i].orderCode + '</span>' +
                        //    ' <span style="margin-left: 3%;margin-top:10px; width: 90%; float: left ">' + pro + '</span>'+
                        //    //'<span style="margin-left: 3%;margin-top:10px; width: 90%; float: left ">计划数/完成数：' + num +'</span></div>'            
                        //    '<span style="margin-left: 3%;margin-top:10px; width: 90%; float: left ">订单数/完成数：' + num +'</span>'            
                        //    + '<span style="margin-left: 3%;margin-top:10px; width: 90%; float: left ">计划总数：' + d[i].planNum + '</span></div>'
                        contents += ' <div style ="border:0px solid darkgray;border-radius:5px;height: 50px; width: 19%; background-color:#fff; padding-top:15px; padding-bottom:7px; float:left; margin-right:1%;margin-top:1%" >' +
                            '<span style="margin-left:3%;width:90%;float:left">销售订单号：' + d[i].orderCode + '</span>' +
                            ' <span style="margin-left: 3%;margin-top:10px; width: 90%; float: left ;color:#A23BEC">' + d[i].cuName + '</span></div>'
                    }
                    $('#orderInfo').append(contents);  
              
                } else {
                    layer.msg(rsl.Message);
                }
            }
        });
    }


    layui.use(['laydate'], function () {
        var $ = layui.$;
        var laydate = layui.laydate;
        var nowTime = new Date().valueOf();
        var max = null;
        var start = laydate.render({
            elem: '#sDate',
            trigger: 'click',
            type: 'date',
            format: 'yyyy/MM/dd',
            max: nowTime,
            btns: ['clear', 'confirm'],
            done: function (value, date) {
                endMax = end.config.max;
                end.config.min = date; //最大时间为结束时间的开始值
                end.config.min.month = date.month - 1;
            }
        });
        var end = laydate.render({
            elem: '#eDate',
            trigger: 'click',
            type: 'date',
            max: 4073558400000,
            format: 'yyyy/MM/dd',
            done: function (value, date) {
                if ($.trim(value) == '') {
                    var curDate = new Date();
                    date = { 'date': curDate.getDate(), 'month': curDate.getMonth() + 1, 'year': curDate.getFullYear() };
                }
                start.config.max = date;//最小时间为开始时间的最大值
                start.config.max.month = date.month - 1;
            }
        })
    })


    //排产相关合计数
    function getSumNum() {
        getNeedPg();
        getPgNFinish();
        getBgNum();
    }
    //派工单未完成数
    function NoFinishTask() {
        $.ajax({
            url: "../Statistics/PaiGongTaskNoFinish",
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    var jt = data.Data.split(',')[0];
                    var zt = data.Data.split(',')[1];
                    document.getElementById("pg-nofinish").innerText = parseFloat(jt);
                    if (parseInt(jt) - parseInt(zt) >0 ){
                        $("#pg-nofinish-yesterday").append("<svg class='icon' style='width: 1em;height: 1em;"+
                        "vertical - align: -0.15em;fill: currentColor;overflow: hidden;' aria-hidden='true'>"+
                            "<use xlink: href = '#icon-ttd-copy1' ></use></svg> ");
                        
                    } else {
                        $("#pg-nofinish-yesterday").append("<svg class='icon' style='width: 1em;height: 1em;" +
                            "vertical - align: -0.15em;fill: currentColor;overflow: hidden;' aria-hidden='true'>" +
                            "<use xlink: href = '#icon-ttd-copy' ></use></svg> ");
                    }
                    $("#pg-nofinish-yesterday").append(Math.abs(parseInt(jt) - parseInt(zt)));
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
   /*
    * 不合格
    * */
    function DaysNoQuality() {
        $.ajax({
            url: "../Statistics/DaysBaoGongNo",
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    var jt = data.Data.split(',')[0];
                    var zt = data.Data.split(',')[1];
                    document.getElementById("bg-noQuality").innerText = parseFloat(jt);
                    if (parseFloat(jt) - parseFloat(zt) > 0) {
                        $("#pg-noQuality-yesterday").append("<svg class='icon' style='width: 1em;height: 1em;" +
                            "vertical - align: -0.15em;fill: currentColor;overflow: hidden;' aria-hidden='true'>" +
                            "<use xlink: href = '#icon-ttd-copy1' ></use></svg> ");

                    } else {
                        $("#pg-noQuality-yesterday").append("<svg class='icon' style='width: 1em;height: 1em;" +
                            "vertical - align: -0.15em;fill: currentColor;overflow: hidden;' aria-hidden='true'>" +
                            "<use xlink: href = '#icon-ttd-copy' ></use></svg> ");
                    }
                    $("#pg-noQuality-yesterday").append(Math.abs(parseFloat(jt) - parseFloat(zt)));
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }

  /*
   * 计划未完成
   * */
    function PlanNoFinish() {
        $.ajax({
            url: "../Statistics/PlanNoFinish",
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    document.getElementById("pnofinish").innerText = data.Data;
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
    /**
     * 派工延期未完成
     * */
    function TaskDelay() {
        $.ajax({
            url: "../Statistics/TaskDelayCount",
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    var jt = data.Data.split(',')[0];
                    var zt = data.Data.split(',')[1];
                    document.getElementById("pg-delay").innerText = parseFloat(jt);
                    if (parseFloat(jt) - parseFloat(zt) > 0) {
                        $("#pg-delay-yesterday").append("<svg class='icon' style='width: 1em;height: 1em;" +
                            "vertical - align: -0.15em;fill: currentColor;overflow: hidden;' aria-hidden='true'>" +
                            "<use xlink: href = '#icon-ttd-copy1' ></use></svg> ");

                    } else {
                        $("#pg-delay-yesterday").append("<svg class='icon' style='width: 1em;height: 1em;" +
                            "vertical - align: -0.15em;fill: currentColor;overflow: hidden;' aria-hidden='true'>" +
                            "<use xlink: href = '#icon-ttd-copy' ></use></svg> ");
                    }
                    $("#pg-delay-yesterday").append(Math.abs(parseFloat(jt) - parseFloat(zt)));
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }
    
</script>